from openai import OpenAI
import api_config


def get_response(userQuery, yolo, image_description):
    client = OpenAI(api_key=api_config.api_key, base_url=api_config.base_url)
    completion = client.chat.completions.create(
        model="qwen-plus",
        messages=[
            {"role": "system", "content": "You are a helpful assistant for guide. And your will talk to the blinds."},
            {
                "role": "user",
                "content": f"{userQuery}另外，YOLO的描述是：{yolo}"
                f"这是整体描述：{image_description}",
            },
        ],
        temperature=0.7,
        top_p=0.8,
    )
    response_content = completion.choices[0].message.content
    # print(response_content)
    return response_content

def getNlpResponds(yolo="无", image_description="无"):
    userQuery = "请将下面的结构化的视野中图像描述概括为自然语言描述，用中文回答，尽可能的口语化与简练。"
    return get_response(userQuery, yolo, image_description)

# 例子
if __name__ == "__main__":
    example_yolo = {
        " 1 car for 80%，position =（0.5，0.7）at percentage，size = （0.1，0.1）at percentage in image，distance=6meter"
    }
    example_image_description = (
        "A picture of a park with trees, a lake, and people walking."
    )
    userQuery = "请你帮忙结合输出的物体位置，描述成实际生活中用于指导盲人的一句话（使用中文,尽可能简短一点，）" 
    get_response(userQuery, example_yolo, example_image_description)
